package com.sm.dao;

import com.sm.entity.Notice;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NoticeDao {
    //查询
    @Select("select * from notice")
    public List<Notice> findAllNotice();

    @Select("select * from notice where nid = #{nid}")
    public Notice findNotieNid(Integer nid);
    //添加
    @Insert("insert into notice(content,date,status) values(#{content},#{date},#{status})")
    public void addNotice(Notice notice);
    //修改
    @Update("update notice set content = #{content},status = #{status} where nid = #{nid}")
    public void updateNotice(Notice notice);

    @Update("update notice set status = #{status} where nid = #{nid}")
    public void updateStatus(Notice notice);
    //删除
    @Update("update notice set status = 0 where nid = #{nid}")
    public void deleteNotice(Integer nid);

    @Delete("delete from notice where nid = #{nid}")
    public void clearNotice(Integer nid);

    //获取最新的通告
    @Select("select * from notice where status = 1 order by date desc,nid desc  limit #{limit}")
    public List<Notice> findNowNotice(Integer limit)throws Exception;
}
